const log4js = require('log4js')
const logLayout = {
  type: 'pattern',
  pattern: '[%[%p%]] %d{yyyy-MM-dd hh:mm:ss} %h %[%f{2}:%l%] %m%n'
}

log4js.configure({
  appenders: {
    console: { type: 'console', layout: logLayout },
    file: {
      type: 'dateFile',
      filename: 'logs/app',
      encoding: 'utf-8',
      pattern: 'yyyy-MM-dd.log',
      layout: {
        type: 'pattern',
        pattern: '[%p] %d{yyyy-MM-dd hh:mm:ss} %h %f{2}:%l %m%n'
      },
      alwaysIncludePattern: true,
      numBackups: 90,
      keepFileExt: true // 保留扩展名
    }
  },
  categories: {
    default: {
      appenders: ['console', 'file'],
      level: 'debug',
      enableCallStack: true
    }
  }
})

module.exports = log4js
